import { Body, Controller, OnModuleInit, Post } from '@nestjs/common';
import {EmailDto} from './email.dto';
import { ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Client,type ClientGrpc } from '@nestjs/microservices';
import { emailGrpcClientOptions } from './email.client';
import { EmailServiceClient } from '@libs/common/protos/email/email';
@ApiTags('邮件服务')
@Controller('email')
export class EmailController implements OnModuleInit{
  @Client(emailGrpcClientOptions)
  private readonly emailClient: ClientGrpc;

  private emailServiceClient: EmailServiceClient;
  onModuleInit(): any {
    this.emailServiceClient = this.emailClient.getService<EmailServiceClient>('EmailService');
  }
  @ApiOperation({
    summary: '发送欢迎邮件',
    description: '用户注册成功后发送欢迎邮件（基于 gRPC 类型）',
  })
  @ApiResponse({ status: 200, description: '邮件发送成功' })
  @ApiResponse({ status: 400, description: '参数错误' })
  @ApiBody({ type: EmailDto })
  @Post('send-welcome-email')
  sendWelcomeEmail(@Body() data: EmailDto) {
    return this.emailServiceClient.send(data);
  }


}
